This page just serves as a quick reminder for creating different objects.
Creating Objects :

Filled or framed rectangles: FramedRect(x coordinate, y coordinate, width, height, canvas); the default color for filled objects is black

Filled or framed ovals: FramedOval(x coordinate, y coordinate, width, height, canvas);

Lines: Line(starting x coordinate, starting y coordinate, ending x, ending y, canvas);

Text: Text("what you want printed", x, y, canvas);

Filled or framed arcs: FramedArc(x, y, width of circle, height of circle, starting angle in degrees, degrees away from starting angle, canvas);

Setting Colors :
To set a color for an object, first, you have to make a variable for the object that you make.
So, If you want to set color for a FilledRect, first, set a variable for the object that you've made (EX. private FilledRect theName;),
and now, all you have to do is to write the code(EX. theName.setColor(Color.red); ) below the line where you created the object.

  • Color.black (sets of colors you can use in objectDrawing, or you could use numbers to set colors)
  • Color.blue
  • Color.cyan
  • Color.darkGray
  • Color.gray
  • Color.green
  • Color.lightGray
  • Color.magenta
  • Color.orange
  • Color.pink
  • Color.red
  • Color.white
  • Color.yellow

Along with the colors already inserted into the Java api, you may also create your own colors using RGB format. The RGB(red, green, blue) format consists of three number, each between 0 and 255. Now for an example.
For example purposes, let's call our object "ball". "ball" is a FilledOval, that is the easiest way to have a colored object.
private FilledOval ball;//creates the ball variable
 
public void begin()
   {
     ball = new FilledOval(0,0,10,10,canvas);
 
     //set the new color
     ball.setColor(new Color ( 255, 255, 0)); //makes the ball a shade of yellow
   }
 
There it is, a custom color is made. It can be really useful when trying to make people, or different shades of laundry*cough*cough*.

Example:
public class Objects extends FrameWindowController
{
   private FramedRect rect1;
   private FilledRect rect2;
   private FramedOval oval1;
   private Line line1;
   private Text message;
   private FilledArc arc1;
 
   public void begin()
   {
       rect1 = new FramedRect(100, 100, 100, 100, canvas);
            rect1.setColor(Color.red);
       rect2 = new FilledRect(101, 101, 99, 99, canvas);
            rect2.setColor(Color.yellow);
       line1 = new Line (120, 120, 182, 182, canvas);
       oval1 = new FramedOval ( 106, 106, 89, 89, canvas);
       message = new Text ("CLICKING", 123, 145, canvas);
       arc1 = new FilledArc (200, 200, 50, 50, 90, 30, canvas);
   }
}
 


There are other methods that are useful for Drawable Objects, such as:
  • .move(a,b) will move the object in the x-direction a amount, & in the y-direction b amount
  • .moveTo(x,y) will move the object to an (x,y) location
  • .hide() will hide the object from view
  • .show() will show the object
  • .sendBackward() will send the object behind other objects on the screen
  • .sendForward() will send the object forward, from behind
  • .getColor() will return the color of the object
  • .getWidth() will return the width of the object
  • .setWidth() will set the width of the object
  • .getHeight() will return the height of the object
  • .setHeight() will set the height of the object
  • .getStart() will return the starting point of the object (mainly for lines, since circles do not have a start)
  • .getEnd() will return the ending point of the object (mainly for lines, since circles do not have a end)
  • .getLocation() will return the location of the object
  • .setEndPoints() will set the end points of an object (lines)
  • .sendToFront() // will send the object to the front of everything


EXAMPLE of making two objects with "if" statement.

import java.awt.*;
import objectdraw.*;
public class ChristmasTree extends FrameWindowController
{
    public void begin()
    {
        makeUpsideDownTree(200,300,100);
        makeSideTree(200, 300, 100);
    }
    public void makeTree(int middle, int y , int length)
    {
        //first thing is a base case
        if ( length <= 0 )
            return;
        else
        {
            //draw the line and recall the method
            Line temp = new Line(middle - length/2, y,
                     middle + length/2, y, canvas);
            temp.setColor(Color.green);
            makeTree(middle, y-2, length-1);
        }
    }
     public void makeUpsideDownTree(int middle, int y , int length)
    {
        //first thing is a base case
        if ( length <= 0 )
            return;
        else
        {
            //draw the line and recall the method
            Line temp = new Line(middle - length/2, y,
                     middle + length/2, y, canvas);
            temp.setColor(Color.green);
            makeUpsideDownTree(middle, y+2, length-1);
        }
 
 
 
    }
    public void makeSideTree(int middle, int y, int length)
    {
       if(length <= 0)
          return;
 
       else
       {
 
           Line temp = new Line(middle, y + length/2,
           middle, y - length/2, canvas);
 
            temp.setColor(Color.green);
            makeSideTree(middle+2,y, length-1);
        }
    }
}